<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: relative;
            width: 400px;
            border-bottom: 1px solid #ccc;
            margin: 100px auto;
        }
        .box input {
            width: 370px;
            height: 30px;
            border: 0;
            outline: 0;
        }
        .box img {
            width: 20px;
            height: 20px;
            top: 25px;
            right: 2px;
            position: absolute;
        }
    </style>
</head>
<body>
        <div class="box">
            用户名<input type="text" id="name"><br>
        </div>
        <div class="box">
            <label for="">
                <img src="C:\java-script_learning\image\yanj1.jpg" alt="">
            </label>
            密码<input type="password" id="pass">
        </div>
        <script>
            var pass = document.querySelector('#pass');
            var btn = document.querySelector('button');
            var image = document.querySelector('img');
            flag = 0;
            image.onclick = function() {
                if(flag == 0) {
                    pass.type = 'text';
                    image.src = 'C:\\java-script_learning\\image\\yanj2.jpg';
                    flag = 1;
                }else {
                    pass.type = 'password';
                    image.src = 'C:\\java-script_learning\\image\\yanj1.jpg';
                    flag = 0;
                }
            }

        </script>
</body>
</html>